package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseRVAdapter;
import com.wnhz.work.yz.base.BaseViewHolder;
import com.wnhz.work.yz.bean.BiaoZhunBean;
import com.wnhz.work.yz.bean.ErciBean;
import com.wnhz.work.yz.utils.AlbumImagePath;
import com.wnhz.work.yz.utils.BitnapUtils;
import com.wnhz.work.yz.utils.Url;
import com.wnhz.work.yz.utils.xutils3.MyCallBack;
import com.wnhz.work.yz.utils.xutils3.XUtil;
import com.wnhz.work.yz.view.SkillBookPop;
import com.wnhz.work.yz.view.SwitchView;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.x;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

public class YanShouErCiGaiActivity extends BaseActivity implements View.OnClickListener {
    private RecyclerView recycler, img;
    private List<String> list = new ArrayList<>();
    private BaseRVAdapter adapter;
    private ErciBean bean = new ErciBean();

    private RecyclerView max_re;
    private TextView name;
    private EditText content;
    private RecyclerView biaozhun;
    private EditText status, shuoming;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yan_shou_er_ci_gai);
        bean = (ErciBean) getIntent().getSerializableExtra("bean");
        if (bean == null) {
            MyToast("暂无数据");
            return;
        }

        content = (EditText) findViewById(R.id.content123);
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("" + bean.getInfo().getName());
        TextView name = (TextView) findViewById(R.id.name);
        name.setText("" + bean.getInfo().getBudget_no());
        TextView hetong = (TextView) findViewById(R.id.hetong);
        hetong.setText("合同编号：" + bean.getInfo().getContract_id());
        ImageView img2 = (ImageView) findViewById(R.id.img);
        x.image().bind(img2, bean.getInfo().getImg());
        TextView sname = (TextView) findViewById(R.id.sname);
        sname.setText("" + bean.getInfo().getName());
        TextView install = (TextView) findViewById(R.id.install);
        install.setText("安装队：" + bean.getInfo().getInstall());
        TextView ss = (TextView) findViewById(R.id.ss);
        ss.setText("" + bean.getInfo().getLabel());
        TextView info = (TextView) findViewById(R.id.info);
        info.setText("" + bean.getInfo().getInfo());

        findViewById(R.id.btn_main_left).setOnClickListener(this);
        TextView submit = (TextView) findViewById(R.id.submit);
        submit.setText("保存");
        submit.setTextSize(12);
        submit.setVisibility(View.VISIBLE);
        submit.setOnClickListener(this);
        //
        max_re = (RecyclerView) findViewById(R.id.max_re);
        max_re.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        final List<ErciBean.InfoEntity.ProgressEntity> progress = bean.getInfo().getProgress();
        max_re.setAdapter(new BaseRVAdapter(this, progress) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_yanshou999;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.setTextView(R.id.cishu, "第" + (position + 1) + "次验收");
                holder.setTextView(R.id.time, "安装队：" + progress.get(position).getInstaller());
                holder.setTextView(R.id.fen, progress.get(position).getScore() + "分");
                holder.setTextView(R.id.gai, progress.get(position).getRemark());
                SwitchView switchButton = holder.getView(R.id.switchButton);
                switchButton.setFlag(false);
                if ("1".equals(progress.get(position).getIs_punish())) {
                    switchButton.setOpened(true);
                    holder.getView(R.id.chufa).setVisibility(View.VISIBLE);
                    holder.setTextView(R.id.status55, progress.get(position).getPunish_money());
                    holder.setTextView(R.id.shuoming, progress.get(position).getPunish_remark());
                } else {
                    switchButton.setOpened(false);
                    holder.getView(R.id.chufa).setVisibility(View.GONE);
                }
                holder.setTextView(R.id.time, progress.get(position).getCheck_time());

                RecyclerView diyici = holder.getView(R.id.diyici);
                diyici.setLayoutManager(new GridLayoutManager(YanShouErCiGaiActivity.this, 4, LinearLayoutManager.VERTICAL, false));
                final List<String> check_img = progress.get(position).getCheck_img();
                diyici.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, check_img) {
                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.item_photo;
                    }

                    @Override
                    public void onBind(BaseViewHolder holder, final int position) {
                        holder.getImageView(R.id.img).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                intent.putStringArrayListExtra("paths", (ArrayList<String>) check_img);
                                intent.putExtra("index", position);
                                startActivity(intent);
                            }
                        });
                        //x.image().bind(holder.getImageView(R.id.img), bean.getInfo().getCheck_img().get(position));
                        ImageLoader.getInstance().displayImage(check_img.get(position), holder.getImageView(R.id.img));

                    }
                });
            }
        });

        status = (EditText) findViewById(R.id.status33);
        shuoming = (EditText) findViewById(R.id.shuoming);
        biaozhun = (RecyclerView) findViewById(R.id.biaozhun);
        //
        list.add("add");
        img = (RecyclerView) findViewById(R.id.img99);
        img.setLayoutManager(new GridLayoutManager(this, 4, LinearLayoutManager.VERTICAL, false));

        adapter = new BaseRVAdapter(this, list) {

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_photo;
            }

            @Override
            public void onBind(BaseViewHolder holder, final int position) {
                if ("add".equals(list.get(position))) {
                    holder.getView(R.id.cha).setVisibility(View.GONE);
                    holder.getImageView(R.id.img).setImageResource(R.drawable.mq_ic_add_img);
                    holder.getImageView(R.id.img).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            showPopmenu(v);
                        }
                    });
                } else {
                    holder.getImageView(R.id.img).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                        }
                    });
                    holder.getView(R.id.cha).setVisibility(View.VISIBLE);
                    x.image().bind(holder.getImageView(R.id.img), list.get(position));
                    holder.getView(R.id.cha).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            list.remove(position);
                            if (list.size() != 0) {
                                if (!"add".equals(list.get(list.size() - 1))) {
                                    list.add("add");
                                }
                            }
                            notifyDataSetChanged();
                        }
                    });
                }
            }

        };
        img.setAdapter(adapter);
        initBiaoZhun();
    }

    private void initBiaoZhun() {
        biaozhun.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        upLoad2();
    }

    private void upLoad2() {
        Map<String, Object> map = new HashMap<>();
        map.put("type", 4);
        showDialog();

        XUtil.Post(Url.DECORATE_STANDARDFILE, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i("----", "onSuccess:= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    Log.e("----", "onSuccess:= " + info);
                    if ("1".equals(res)) {
                        Gson gson = new Gson();
                        BiaoZhunBean bean = gson.fromJson(result, BiaoZhunBean.class);
                        List<BiaoZhunBean.InfoEntity> info1 = bean.getInfo();
                        setData(info1);

                    } else {
                        if ("-1".equals(res)) {
                            info = "请重新登录";
                        }
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                closeDialog();
                ex.printStackTrace();
            }
        });


    }

    private void setData(final List<BiaoZhunBean.InfoEntity> info1) {
        biaozhun.setAdapter(new BaseRVAdapter(this, info1) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_biaozhun;
            }

            @Override
            public void onBind(BaseViewHolder holder, final int position) {
                //标题内容
                holder.setTextView(R.id.title, info1.get(position).getTitle());
                holder.setTextView(R.id.content, info1.get(position).getDetail());
                //视频
                RecyclerView video = holder.getView(R.id.video);
                video.setLayoutManager(new LinearLayoutManager(YanShouErCiGaiActivity.this, LinearLayoutManager.VERTICAL, false));
                final List<BiaoZhunBean.InfoEntity.VideoEntity> video1 = info1.get(position).getVideo();
                video.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, video1) {
                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.video;
                    }

                    @Override
                    public void onBind(BaseViewHolder holder, int position2) {
                        JCVideoPlayerStandard jcVideoPlayerStandard = holder.getView(R.id.jc);
                        jcVideoPlayerStandard.setUp(video1.get(position2).getVideo_url()
                                , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, info1.get(position).getTitle());
                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(video1.get(position2).getVideo_img(),
                                jcVideoPlayerStandard.thumbImageView);

                    }
                });
                //图片
                final List<String> img = info1.get(position).getImg();
                LinearLayout status1 = holder.getView(R.id.status1);
                LinearLayout status2 = holder.getView(R.id.status2);
                LinearLayout status3 = holder.getView(R.id.status3);
                ImageView img1 = holder.getImageView(R.id.img1);
                ImageView img2_1 = holder.getImageView(R.id.img2_1);
                ImageView img2_2 = holder.getImageView(R.id.img2_2);
                RecyclerView img_recycler = holder.getView(R.id.img_recycler);
                switch (img.size()) {
                    case 0:
                        status1.setVisibility(View.GONE);
                        status2.setVisibility(View.GONE);
                        status3.setVisibility(View.GONE);


                        break;
                    case 1:
                        status1.setVisibility(View.VISIBLE);
                        status2.setVisibility(View.GONE);
                        status3.setVisibility(View.GONE);
                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(0),
                                img1);
                        img1.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                intent.putExtra("index", 0);
                                startActivity(intent);
                            }
                        });
                        break;
                    case 2:
                        status1.setVisibility(View.GONE);
                        status2.setVisibility(View.VISIBLE);
                        status3.setVisibility(View.GONE);
                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(0),
                                img2_1);
                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(1),
                                img2_2);
                        img2_1.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                intent.putExtra("index", 0);
                                startActivity(intent);
                            }
                        });
                        img2_2.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                intent.putExtra("index", 1);
                                startActivity(intent);
                            }
                        });
                        break;
                    default:
                        status1.setVisibility(View.GONE);
                        status2.setVisibility(View.GONE);
                        status3.setVisibility(View.VISIBLE);
                        img_recycler.setLayoutManager(new GridLayoutManager(YanShouErCiGaiActivity.this, 3, LinearLayoutManager.VERTICAL, false));
                        img_recycler.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, img) {
                            @Override
                            public int getLayoutId(int viewType) {
                                return R.layout.item_photo;
                            }

                            @Override
                            public void onBind(BaseViewHolder holder, final int position) {
                                holder.getImageView(R.id.img).setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                        intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                        intent.putExtra("index", position);
                                        startActivity(intent);
                                    }
                                });
                                ImageLoader.getInstance().displayImage(img.get(position), holder.getImageView(R.id.img));

                            }

                        });

                        break;
                }
                //子类
                RecyclerView recycler = holder.getView(R.id.recycler);
                recycler.setLayoutManager(new LinearLayoutManager(YanShouErCiGaiActivity.this, LinearLayoutManager.VERTICAL, false));
                final List<BiaoZhunBean.InfoEntity.CateEntity> cate = info1.get(position).getCate();
                recycler.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, cate) {
                    @Override
                    public int getLayoutId(int viewType) {
                        return R.layout.item_biaozhun2;
                    }

                    @Override
                    public void onBind(BaseViewHolder holder, final int position) {
                        //标题内容
                        holder.setTextView(R.id.title, cate.get(position).getTitle());
                        holder.setTextView(R.id.content, cate.get(position).getDetail());
                        //视频
                        RecyclerView video = holder.getView(R.id.video);
                        video.setLayoutManager(new LinearLayoutManager(YanShouErCiGaiActivity.this, LinearLayoutManager.VERTICAL, false));
                        final List<BiaoZhunBean.InfoEntity.CateEntity.VideoEntity> video1 = cate.get(position).getVideo();
                        video.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, video1) {
                            @Override
                            public int getLayoutId(int viewType) {
                                return R.layout.video;
                            }

                            @Override
                            public void onBind(BaseViewHolder holder, int position2) {
                                JCVideoPlayerStandard jcVideoPlayerStandard = holder.getView(R.id.jc);
                                jcVideoPlayerStandard.setUp(video1.get(position2).getVideo_url()
                                        , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, cate.get(position).getTitle());
                                com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(video1.get(position2).getVideo_img(),
                                        jcVideoPlayerStandard.thumbImageView);

                            }
                        });
                        //图片
                        final List<String> img = cate.get(position).getImg();
                        LinearLayout status1 = holder.getView(R.id.status1);
                        LinearLayout status2 = holder.getView(R.id.status2);
                        LinearLayout status3 = holder.getView(R.id.status3);
                        ImageView img1 = holder.getImageView(R.id.img1);
                        ImageView img2_1 = holder.getImageView(R.id.img2_1);
                        ImageView img2_2 = holder.getImageView(R.id.img2_2);
                        RecyclerView img_recycler = holder.getView(R.id.img_recycler);
                        switch (img.size()) {
                            case 0:
                                status1.setVisibility(View.GONE);
                                status2.setVisibility(View.GONE);
                                status3.setVisibility(View.GONE);


                                break;
                            case 1:
                                status1.setVisibility(View.VISIBLE);
                                status2.setVisibility(View.GONE);
                                status3.setVisibility(View.GONE);
                                com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(0),
                                        img1);
                                img1.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                        intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                        intent.putExtra("index", 0);
                                        startActivity(intent);
                                    }
                                });
                                break;
                            case 2:
                                status1.setVisibility(View.GONE);
                                status2.setVisibility(View.VISIBLE);
                                status3.setVisibility(View.GONE);
                                com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(0),
                                        img2_1);
                                com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(1),
                                        img2_2);
                                img2_1.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                        intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                        intent.putExtra("index", 0);
                                        startActivity(intent);
                                    }
                                });
                                img2_2.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                        intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                        intent.putExtra("index", 1);
                                        startActivity(intent);
                                    }
                                });
                                break;
                            default:
                                status1.setVisibility(View.GONE);
                                status2.setVisibility(View.GONE);
                                status3.setVisibility(View.VISIBLE);
                                img_recycler.setLayoutManager(new GridLayoutManager(YanShouErCiGaiActivity.this, 3, LinearLayoutManager.VERTICAL, false));
                                img_recycler.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, img) {
                                    @Override
                                    public int getLayoutId(int viewType) {
                                        return R.layout.item_photo;
                                    }

                                    @Override
                                    public void onBind(BaseViewHolder holder, final int position) {
                                        holder.getImageView(R.id.img).setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                                intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                                intent.putExtra("index", position);
                                                startActivity(intent);
                                            }
                                        });
                                        ImageLoader.getInstance().displayImage(img.get(position), holder.getImageView(R.id.img));

                                    }

                                });

                                break;
                        }

                        RecyclerView recycler = holder.getView(R.id.recycler);
                        recycler.setLayoutManager(new LinearLayoutManager(YanShouErCiGaiActivity.this, LinearLayoutManager.VERTICAL, false));
                        final List<BiaoZhunBean.InfoEntity.CateEntity.ChildEntity> child = cate.get(position).getChild();
                        recycler.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, child) {
                            @Override
                            public int getLayoutId(int viewType) {
                                return R.layout.item_biaozhun3;
                            }

                            @Override
                            public void onBind(BaseViewHolder holder, final int position) {

                                //标题内容
                                holder.setTextView(R.id.title, child.get(position).getTitle());
                                holder.setTextView(R.id.content, child.get(position).getDetail());
                                //视频
                                RecyclerView video = holder.getView(R.id.video);
                                video.setLayoutManager(new LinearLayoutManager(YanShouErCiGaiActivity.this, LinearLayoutManager.VERTICAL, false));
                                final List<BiaoZhunBean.InfoEntity.CateEntity.ChildEntity.VideoEntity> video1 = child.get(position).getVideo();
                                video.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, video1) {
                                    @Override
                                    public int getLayoutId(int viewType) {
                                        return R.layout.video;
                                    }

                                    @Override
                                    public void onBind(BaseViewHolder holder, int position2) {
                                        JCVideoPlayerStandard jcVideoPlayerStandard = holder.getView(R.id.jc);
                                        jcVideoPlayerStandard.setUp(video1.get(position2).getVideo_url()
                                                , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, child.get(position).getTitle());
                                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(video1.get(position2).getVideo_img(),
                                                jcVideoPlayerStandard.thumbImageView);

                                    }
                                });
                                //图片
                                final List<String> img = child.get(position).getImg();
                                LinearLayout status1 = holder.getView(R.id.status1);
                                LinearLayout status2 = holder.getView(R.id.status2);
                                LinearLayout status3 = holder.getView(R.id.status3);
                                ImageView img1 = holder.getImageView(R.id.img1);
                                ImageView img2_1 = holder.getImageView(R.id.img2_1);
                                ImageView img2_2 = holder.getImageView(R.id.img2_2);
                                RecyclerView img_recycler = holder.getView(R.id.img_recycler);
                                switch (img.size()) {
                                    case 0:
                                        status1.setVisibility(View.GONE);
                                        status2.setVisibility(View.GONE);
                                        status3.setVisibility(View.GONE);


                                        break;
                                    case 1:
                                        status1.setVisibility(View.VISIBLE);
                                        status2.setVisibility(View.GONE);
                                        status3.setVisibility(View.GONE);
                                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(0),
                                                img1);
                                        img1.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                                intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                                intent.putExtra("index", 0);
                                                startActivity(intent);
                                            }
                                        });
                                        break;
                                    case 2:
                                        status1.setVisibility(View.GONE);
                                        status2.setVisibility(View.VISIBLE);
                                        status3.setVisibility(View.GONE);
                                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(0),
                                                img2_1);
                                        com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(img.get(1),
                                                img2_2);
                                        img2_1.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                                intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                                intent.putExtra("index", 0);
                                                startActivity(intent);
                                            }
                                        });
                                        img2_2.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                                intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                                intent.putExtra("index", 1);
                                                startActivity(intent);
                                            }
                                        });
                                        break;
                                    default:
                                        status1.setVisibility(View.GONE);
                                        status2.setVisibility(View.GONE);
                                        status3.setVisibility(View.VISIBLE);
                                        img_recycler.setLayoutManager(new GridLayoutManager(YanShouErCiGaiActivity.this, 3, LinearLayoutManager.VERTICAL, false));
                                        img_recycler.setAdapter(new BaseRVAdapter(YanShouErCiGaiActivity.this, img) {
                                            @Override
                                            public int getLayoutId(int viewType) {
                                                return R.layout.item_photo;
                                            }

                                            @Override
                                            public void onBind(BaseViewHolder holder, final int position) {
                                                holder.getImageView(R.id.img).setOnClickListener(new View.OnClickListener() {
                                                    @Override
                                                    public void onClick(View v) {
                                                        Intent intent = new Intent(YanShouErCiGaiActivity.this, ShowImageDetail.class);
                                                        intent.putStringArrayListExtra("paths", (ArrayList<String>) img);
                                                        intent.putExtra("index", position);
                                                        startActivity(intent);
                                                    }
                                                });
                                                ImageLoader.getInstance().displayImage(img.get(position), holder.getImageView(R.id.img));

                                            }

                                        });

                                        break;
                                }
                            }


                        });

                    }
                });

            }

        });

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.submit:
                upLoad();
                break;
        }
    }

    private void upLoad() {
        if (list.size() == 1) {
            MyToast("至少上传一张图片");
            return;
        }

        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("pid", "" + getIntent().getStringExtra("pid"));
        map.put("type", "" + getIntent().getStringExtra("type"));
        map.put("content", content.getText());

        for (int h = 0; h < list.size(); h++) {
            if (!"add".equals(list.get(h))) {
                String compressImage = BitnapUtils.compressImage(list.get(h), list.get(h), 30);
                File compressedPic = new File(compressImage);
                map.put("list" + (h + 1), compressedPic);
            }
        }

//        is_punish（0和1）、punish_money、punish_remark


        Set keys = map.keySet();
        if (keys != null) {
            Iterator iterator = keys.iterator();
            while (iterator.hasNext()) {
                Object key = iterator.next();
                Object value = map.get(key);
                Log.e("----" + key, "" + value + "\n");
            }
        }
        XUtil.Post(Url.DECORATE_UPLOADMODIFYRESULT, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.i("----", "onSuccess:= " + result);
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String res = jsonObject.optString("result");
                    String info = jsonObject.optString("info");
                    Log.e("----", "onSuccess:= " + info);
                    if ("1".equals(res)) {
                        Gson gson = new Gson();
                        MyToast(info);
                        finish();
                    } else {
                        if ("-1".equals(res)) {
                            info = "请重新登录";
                        }
                        MyToast(info);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished() {
                closeDialog();
                super.onFinished();
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
                closeDialog();
                ex.printStackTrace();
            }
        });

    }


    /**
     * ------头像点击
     */
    private WindowManager.LayoutParams lp;
    private SkillBookPop menuWindow;
    private final int FROM_CAMERA_CODE = 111;// 调用相机更改背景图片的请求code
    private final int FROM_ALBUM_CODE = 112;// 调用相册更改背景图片的请求code
    private String imageName;// 原图名称
    private String imagePath;// 原图路径
    private File tempFile;

    /**
     * 图片上传的弹出popwindow
     *
     * @param view
     */
    public void showPopmenu(View view) {
        menuWindow = new SkillBookPop(this, menuItemsOnClick);
        menuWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

            public void onDismiss() {
                WindowManager.LayoutParams lp = getWindow().getAttributes();
                lp.alpha = 1f;
                getWindow().setAttributes(lp);
            }
        });

        // 显示窗口位置
        menuWindow.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        // 设置layout在PopupWindow中显示的位置
        lp = getWindow().getAttributes();
        lp.alpha = 0.6f;
        getWindow().setAttributes(lp);
    }

    /**
     * 弹出pop的菜单点击事件
     */
    private View.OnClickListener menuItemsOnClick = new View.OnClickListener() {
        Intent intent = null;

        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                case R.id.from_camera2:

                    intent = new Intent("android.media.action.IMAGE_CAPTURE");
                    // 判断存储卡是否可以用，可用进行存储
                    if (hasSdcard()) {
                        String time = System.currentTimeMillis() + "";
                        imageName = time + ".jpg";
                        intent.putExtra(MediaStore.EXTRA_OUTPUT,
                                Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/youZhu/", imageName)));
                    }
                    intent.putExtra("crop", "true");

                    // aspectX aspectY 是宽高的比例
                    intent.putExtra("aspectX", 1);
                    intent.putExtra("aspectY", 2);

                    // outputX,outputY 是剪裁图片的宽高
                    intent.putExtra("outputX", 100);
                    intent.putExtra("outputY", 200);

                    startActivityForResult(intent, FROM_CAMERA_CODE);


                    break;
                case R.id.from_album2:

                    Intent intent = new Intent(Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    startActivityForResult(intent, FROM_ALBUM_CODE);

                    break;

                default:
                    break;
            }
        }
    };

    private boolean hasSdcard() {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            //相册
            case FROM_ALBUM_CODE:

                if (null != data) {
                    // 得到图片的全路径
                    Uri uri = data.getData();
                    String imagePath = AlbumImagePath.getPath(this, uri);
                    System.out.println("imagePath**====www==" + imagePath);
                    updateImage(imagePath, uri);
                }
                break;
            //拍照
            case FROM_CAMERA_CODE:
                boolean hasSdcard = hasSdcard();
                if (hasSdcard) {
                    tempFile = new File(Environment.getExternalStorageDirectory() + "/youZhu/", imageName);
                    Uri uri = Uri.fromFile(tempFile);
                    String imagePath = tempFile.getAbsolutePath();
                    File file = new File(imagePath);
                    if (!file.exists()) {
                        return;
                    }
                    updateImage(imagePath, uri);
                } else {
                    MyToast("未找到存储卡，无法存储照片！");
                }
                break;


            default:
                break;
        }

    }

    private void updateImage(String imagePath, Uri uri) {
        if (null == imagePath) {
            return;
        }
        //  x.image().bind(iv_edit_head, "file://" + imagePath, options);

        if (list.size() < 4) {
            list.add(list.size() - 1, imagePath);
            adapter.notifyDataSetChanged();
        } else {
            list.add(list.size() - 1, imagePath);
            list.remove(list.size() - 1);
            adapter.notifyDataSetChanged();
        }
        Log.e("img", list.size() + "");
    }
}
